
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Vue  keep-alive · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Vue - 过渡与动画transition.html" />
    
    
    <link rel="prev" href="TypeError Cannot read property 'compilation' of undefined.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../cmd命令.html">
            
                <a href="../cmd命令.html">
            
                    
                    cmd命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Array.prototype.slice.call.html">
            
                <a href="Array.prototype.slice.call.html">
            
                    
                    Array.prototype.slice.call解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="async 函数.html">
            
                <a href="async 函数.html">
            
                    
                    async 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="callback&&callback如果存在回调函数就执行.html">
            
                <a href="callback&&callback如果存在回调函数就执行.html">
            
                    
                    callback&&callback() 如果存在回调函数就执行！
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="CSS3 nth-child使用注意.html">
            
                <a href="CSS3 nth-child使用注意.html">
            
                    
                    CSS3 nth-child(n)使用注意
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="css3的 -webkit-min-device-pixel-ratio属性 解决高清的适配.html">
            
                <a href="css3的 -webkit-min-device-pixel-ratio属性 解决高清的适配.html">
            
                    
                    css3的 -webkit-min-device-pixel-ratio属性 解决高清的适配
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="CSS文本超出自动缩小字体.html">
            
                <a href="CSS文本超出自动缩小字体.html">
            
                    
                    CSS文本超出自动缩小字体
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="element-ui默认样式修改.html">
            
                <a href="element-ui默认样式修改.html">
            
                    
                    element-ui默认样式修改
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="JavaScript setInterval函数详解.html">
            
                <a href="JavaScript setInterval函数详解.html">
            
                    
                    JavaScript setInterval() 函数详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="JavaScript概念之screenclientoffsetscrollinneravail的widthleft.html">
            
                <a href="JavaScript概念之screenclientoffsetscrollinneravail的widthleft.html">
            
                    
                    JavaScript概念之screenclientoffsetscrollinneravail的widthleft
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="js获取星期几.html">
            
                <a href="js获取星期几.html">
            
                    
                    js获取星期几
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="js监听滚动条事件和获取浏览器及屏幕高度和宽度等信息的方法.html">
            
                <a href="js监听滚动条事件和获取浏览器及屏幕高度和宽度等信息的方法.html">
            
                    
                    js监听滚动条事件和获取浏览器及屏幕高度和宽度等信息的方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="js时间戳与日期格式之间相互转换.html">
            
                <a href="js时间戳与日期格式之间相互转换.html">
            
                    
                    js时间戳与日期格式之间相互转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="JS数组reduce方法详解及高级技巧.html">
            
                <a href="JS数组reduce方法详解及高级技巧.html">
            
                    
                    JS数组reduce()方法详解及高级技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="js中获取时间new Date详细介绍.html">
            
                <a href="js中获取时间new Date详细介绍.html">
            
                    
                    js中获取时间new Date()详细介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.html">
            
                <a href="less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法.html">
            
                    
                    less传参问题：在url中插入变量今天在需要用less给url传递参数时遇到了小问题，一番搜索后有了下述解决方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="moment 和date-fns.html">
            
                <a href="moment 和date-fns.html">
            
                    
                    moment 和date-fns
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="node.JS中配置http-server.html">
            
                <a href="node.JS中配置http-server.html">
            
                    
                    node.JS中配置http-server
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="Object.keys详解.html">
            
                <a href="Object.keys详解.html">
            
                    
                    Object.keys详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="router-link各种属性解释.html">
            
                <a href="router-link各种属性解释.html">
            
                    
                    router-link各种属性解释
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="stylus使用介绍.html">
            
                <a href="stylus使用介绍.html">
            
                    
                    stylus使用介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="TypeError Cannot read property 'compilation' of undefined.html">
            
                <a href="TypeError Cannot read property 'compilation' of undefined.html">
            
                    
                    TypeError Cannot read property 'compilation' of undefined
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.24" data-path="Vue  keep-alive.html">
            
                <a href="Vue  keep-alive.html">
            
                    
                    Vue  keep-alive
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.25" data-path="Vue - 过渡与动画transition.html">
            
                <a href="Vue - 过渡与动画transition.html">
            
                    
                    Vue - 过渡与动画transition
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.26" data-path="vue-axios使用方法.html">
            
                <a href="vue-axios使用方法.html">
            
                    
                    vue-axios使用方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.27" data-path="vue-calendar-component.html">
            
                <a href="vue-calendar-component.html">
            
                    
                    vue-calendar-component
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.28" data-path="vue-infinite-loading.html">
            
                <a href="vue-infinite-loading.html">
            
                    
                    vue-infinite-loading
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.29" data-path="vue报错There are multiple modules with names that only differ in casing.html">
            
                <a href="vue报错There are multiple modules with names that only differ in casing.html">
            
                    
                    vue报错There are multiple modules with names that only differ in casing
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.30" data-path="Vue中注意target和currentTarget的使用.html">
            
                <a href="Vue中注意target和currentTarget的使用.html">
            
                    
                    Vue中注意target和currentTarget的使用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.31" data-path="关于给javascript对象添加、删除、修改对象的属性.html">
            
                <a href="关于给javascript对象添加、删除、修改对象的属性.html">
            
                    
                    关于给javascript对象添加、删除、修改对象的属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.32" data-path="获取当前地址坐标.html">
            
                <a href="获取当前地址坐标.html">
            
                    
                    获取当前地址坐标
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.33" data-path="解决ajax跨域问题【5种解决方案】.html">
            
                <a href="解决ajax跨域问题【5种解决方案】.html">
            
                    
                    解决ajax跨域问题【5种解决方案】
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.34" data-path="解决vue-cli webpack打包后加载资源的路径问题.html">
            
                <a href="解决vue-cli webpack打包后加载资源的路径问题.html">
            
                    
                    解决vue-cli webpack打包后加载资源的路径问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.35" data-path="时间格式转换：201971转换为2019-7-1.html">
            
                <a href="时间格式转换：201971转换为2019-7-1.html">
            
                    
                    时间格式转换：201971转换为2019-7-1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.36" data-path="数据库密码改了.html">
            
                <a href="数据库密码改了.html">
            
                    
                    数据库密码改了
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.37" data-path="语法getBoundingClientRect.html">
            
                <a href="语法getBoundingClientRect.html">
            
                    
                    语法getBoundingClientRect()
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.38" data-path="在js中使用length报错Error in renderTypeErrorcannot read property bgImg of null.html">
            
                <a href="在js中使用length报错Error in renderTypeErrorcannot read property bgImg of null.html">
            
                    
                    在js中使用length报错Error in renderTypeErrorcannot read property bgImg of null
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Vue  keep-alive</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="vue--keep-alive">Vue / keep-alive</h1>
<h6 id="keep-alive">keep-alive</h6>
<p>keep-alive&#x662F;Vue&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7EC4;&#x4EF6;&#xFF0C;&#x7528;&#x6765;&#x5BF9;&#x7EC4;&#x4EF6;&#x8FDB;&#x884C;&#x7F13;&#x5B58;&#xFF0C;&#x4ECE;&#x800C;&#x8282;&#x7701;&#x6027;&#x80FD;&#xFF0C;&#x7531;&#x4E8E;&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7EC4;&#x4EF6;&#xFF0C;&#x6240;&#x4EE5;&#x5728;v&#x9875;&#x9762;&#x6E32;&#x67D3;&#x5B8C;&#x6BD5;&#x540E;&#x4E0D;&#x4F1A;&#x88AB;&#x6E32;&#x67D3;&#x6210;&#x4E00;&#x4E2A;DOM&#x5143;&#x7D20;</p>
<pre><code>&lt;keep-alive&gt;
    &lt;loading&gt;&lt;/loading&gt;
&lt;/keep-laive&gt;
</code></pre><p>&#x5F53;&#x7EC4;&#x4EF6;&#x5728;keep-alive&#x5185;&#x88AB;&#x5207;&#x6362;&#x65F6;&#x7EC4;&#x4EF6;&#x7684;<strong>activated&#x3001;deactivated</strong>&#x8FD9;&#x4E24;&#x4E2A;&#x751F;&#x547D;&#x5468;&#x671F;&#x94A9;&#x5B50;&#x51FD;&#x6570;&#x4F1A;&#x88AB;&#x6267;&#x884C;</p>
<p>&#x88AB;&#x5305;&#x88F9;&#x5728;keep-alive&#x4E2D;&#x7684;&#x7EC4;&#x4EF6;&#x7684;&#x72B6;&#x6001;&#x5C06;&#x4F1A;&#x88AB;&#x4FDD;&#x7559;&#xFF0C;&#x4F8B;&#x5982;&#x6211;&#x4EEC;&#x5C06;&#x67D0;&#x4E2A;&#x5217;&#x8868;&#x7C7B;&#x7EC4;&#x4EF6;&#x5185;&#x5BB9;&#x6ED1;&#x52A8;&#x5230;&#x7B2C;100&#x6761;&#x4F4D;&#x7F6E;&#xFF0C;&#x90A3;&#x4E48;&#x6211;&#x4EEC;&#x5728;&#x5207;&#x6362;&#x5230;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x540E;&#x518D;&#x6B21;&#x5207;&#x6362;&#x56DE;&#x5230;&#x8BE5;&#x7EC4;&#x4EF6;&#xFF0C;&#x8BE5;&#x7EC4;&#x4EF6;&#x7684;&#x4F4D;&#x7F6E;&#x72B6;&#x6001;&#x4F9D;&#x65E7;&#x4F1A;&#x4FDD;&#x6301;&#x5728;&#x7B2C;100&#x6761;&#x5217;&#x8868;&#x5904;</p>
<p><img src="https:////upload-images.jianshu.io/upload_images/2808208-dd53a01a61b7554d.gif?imageMogr2/auto-orient/strip%7CimageView2/2/w/370" alt="img"></p>
<p>keep-alive&#x4FDD;&#x7559;&#x72B6;&#x6001;.gif</p>
<p>&#x5173;&#x4E8E;&#x8FD9;&#x4E00;&#x70B9;&#x4E5F;&#x662F;&#x4EC1;&#x8005;&#x89C1;&#x4EC1;&#xFF0C;&#x6709;&#x7684;&#x4EA7;&#x54C1;&#x53EF;&#x80FD;&#x4F1A;&#x8981;&#x6C42;&#x5728;&#x6BCF;&#x4E00;&#x6B21;&#x8FDB;&#x5165;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x65F6;&#x9875;&#x9762;&#x7684;&#x521D;&#x59CB;&#x4F4D;&#x7F6E;&#x90FD;&#x662F;&#x4FDD;&#x6301;&#x5728;&#x9876;&#x90E8;&#x7684;&#xFF0C;&#x8FD9;&#x91CC;&#x53EF;&#x4EE5;&#x5229;&#x7528;Vue&#x4E2D;&#x7684;&#x6EDA;&#x52A8;&#x884C;&#x4E3A;&#xFF0C;&#x4F46;&#x662F;&#x524D;&#x63D0;&#x662F;&#x4F60;&#x662F;<strong>HTML5 history&#x6A21;&#x5F0F;</strong>
 &#x6211;&#x4EEC;&#x5728;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;router&#x5B9E;&#x4F8B;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x53EF;&#x4EE5;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;scrollBehavior&#x65B9;&#x6CD5;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x4F1A;&#x5728;&#x7528;&#x6237;&#x5207;&#x6362;&#x8DEF;&#x7531;&#x65F6;&#x89E6;&#x53D1;</p>
<pre><code>const router=new VueRouter({
        routes:[
            {
                path:&quot;/&quot;,
                component:Home
            }
        ],
        scrollBehavior(to,form,savedPosition){
        //scrollBehavior&#x65B9;&#x6CD5;&#x63A5;&#x6536;to&#xFF0C;form&#x8DEF;&#x7531;&#x5BF9;&#x8C61;
        //&#x7B2C;&#x4E09;&#x4E2A;&#x53C2;&#x6570;savedPosition&#x5F53;&#x4E14;&#x4EC5;&#x5F53;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x524D;&#x8FDB;&#x540E;&#x9000;&#x6309;&#x94AE;&#x89E6;&#x53D1;&#x65F6;&#x624D;&#x53EF;&#x7528;
        //&#x8BE5;&#x65B9;&#x6CD5;&#x4F1A;&#x8FD4;&#x56DE;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#x7684;&#x5BF9;&#x8C61;&#x4FE1;&#x606F;&#xFF0C;&#x5982;&#x679C;&#x8FD4;&#x56DE;false&#xFF0C;&#x6216;&#x8005;&#x662F;&#x4E00;&#x4E2A;&#x7A7A;&#x7684;&#x5BF9;&#x8C61;&#xFF0C;&#x90A3;&#x4E48;&#x4E0D;&#x4F1A;&#x53D1;&#x751F;&#x6EDA;&#x52A8;
        //&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5728;&#x8BE5;&#x65B9;&#x6CD5;&#x4E2D;&#x8BBE;&#x7F6E;&#x8FD4;&#x56DE;&#x503C;&#x6765;&#x6307;&#x5B9A;&#x9875;&#x9762;&#x7684;&#x6EDA;&#x52A8;&#x4F4D;&#x7F6E;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;
         return {x:0,y:0}
        //&#x8868;&#x793A;&#x5728;&#x7528;&#x6237;&#x5207;&#x6362;&#x8DEF;&#x7531;&#x65F6;&#x8BA9;&#x662F;&#x6240;&#x6709;&#x9875;&#x9762;&#x90FD;&#x8FD4;&#x56DE;&#x5230;&#x9876;&#x90E8;&#x4F4D;&#x7F6E;
        //&#x5982;&#x679C;&#x8FD4;&#x56DE;savedPosition,&#x90A3;&#x4E48;&#x5728;&#x70B9;&#x51FB;&#x540E;&#x9000;&#x6309;&#x94AE;&#x65F6;&#x5C31;&#x4F1A;&#x8868;&#x73B0;&#x7684;&#x50CF;&#x539F;&#x751F;&#x6D4F;&#x89C8;&#x5668;&#x4E00;&#x6837;&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x9875;&#x9762;&#x4F1A;&#x6EDA;&#x52A8;&#x8FC7;&#x5230;&#x4E4B;&#x524D;&#x6309;&#x94AE;&#x70B9;&#x51FB;&#x8DF3;&#x8F6C;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x5927;&#x6982;&#x5199;&#x6CD5;&#x5982;&#x4E0B;&#xFF1A;
         if(savedPosition){
            return savedPosition
         }else{
           return {x:0,y:0}
         }
         //&#x5982;&#x679C;&#x60F3;&#x8981;&#x6A21;&#x62DF;&#x6EDA;&#x52A8;&#x5230;&#x951A;&#x70B9;&#x7684;&#x884C;&#x4E3A;:
         if(to.hash){
           return {
             selector:to.hash
           }
         }
     }
})
</code></pre><p>&#x8FD8;&#x6709;&#x4E00;&#x4E2A;&#x65B9;&#x6CD5;&#x5C31;&#x662F;&#x5229;&#x7528;&#x6211;&#x4EEC;&#x4E0A;&#x9762;&#x8BF4;&#x8FC7;&#x7684;&#xFF0C;&#x5728;keep-alive&#x6FC0;&#x6D3B;&#x4F1A;&#x89E6;&#x53D1;activated&#x94A9;&#x5B50;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x8BE5;&#x51FD;&#x6570;&#x5185;&#x8BBE;&#x7F6E;scrollTop&#x4E3A;0</p>
<p>&#x88AB;keep-alive&#x5305;&#x88F9;&#x7684;&#x52A8;&#x6001;&#x7EC4;&#x4EF6;&#x6216;router-view&#x4F1A;&#x7F13;&#x5B58;&#x4E0D;&#x6D3B;&#x52A8;&#x7684;&#x5B9E;&#x4F8B;&#xFF0C;&#x518D;&#x6B21;&#x88AB;&#x8C03;&#x7528;&#x8FD9;&#x4E9B;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x5B9E;&#x4F8B;&#x4F1A;&#x88AB;&#x518D;&#x6B21;&#x590D;&#x7528;&#xFF0C;&#x5BF9;&#x4E8E;&#x6211;&#x4EEC;&#x7684;&#x67D0;&#x4E9B;&#x4E0D;&#x662F;&#x9700;&#x8981;&#x5B9E;&#x65F6;&#x66F4;&#x65B0;&#x7684;&#x9875;&#x9762;&#x6765;&#x8BF4;&#x5927;&#x5927;&#x51CF;&#x5C11;&#x4E86;&#x6027;&#x80FD;&#x4E0A;&#x7684;&#x6D88;&#x8017;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x518D;&#x6B21;&#x53D1;&#x9001;HTTP&#x8BF7;&#x6C42;&#xFF0C;&#x4F46;&#x662F;&#x540C;&#x6837;&#x4E5F;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x95EE;&#x9898;&#x5C31;&#x662F;&#x88AB;keep-alive&#x5305;&#x88F9;&#x7684;&#x7EC4;&#x4EF6;&#x6211;&#x4EEC;&#x8BF7;&#x6C42;&#x83B7;&#x53D6;&#x7684;&#x6570;&#x636E;&#x4E0D;&#x4F1A;&#x518D;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#x9875;&#x9762;&#xFF0C;&#x8FD9;&#x4E5F;&#x5C31;&#x51FA;&#x73B0;&#x4E86;&#x4F8B;&#x5982;&#x6211;&#x4EEC;&#x4F7F;&#x7528;&#x52A8;&#x6001;&#x8DEF;&#x7531;&#x505A;&#x5339;&#x914D;&#x7684;&#x8BDD;&#x9875;&#x9762;&#x53EA;&#x4F1A;&#x4FDD;&#x6301;&#x7B2C;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;&#x6570;&#x636E;&#x7684;&#x6E32;&#x67D3;&#x7ED3;&#x679C;&#xFF0C;&#x6240;&#x4EE5;&#x9700;&#x8981;&#x6211;&#x4EEC;&#x5728;&#x7279;&#x5B9A;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x5F3A;&#x5236;&#x5237;&#x65B0;&#x67D0;&#x4E9B;&#x7EC4;&#x4EF6;</p>
<ol>
<li><p>&#x5229;&#x7528;include&#x3001;exclude&#x5C5E;&#x6027;</p>
<pre><code>&lt;keep-alive include=&quot;bookLists,bookLists&quot;&gt;
      &lt;router-view&gt;&lt;/router-view&gt;
&lt;/keep-alive&gt;
&lt;keep-alive exclude=&quot;indexLists&quot;&gt;
      &lt;router-view&gt;&lt;/router-view&gt;
&lt;/keep-alive&gt;
</code></pre><p>include&#x5C5E;&#x6027;&#x8868;&#x793A;&#x53EA;&#x6709;name&#x5C5E;&#x6027;&#x4E3A;bookLists&#xFF0C;bookLists&#x7684;&#x7EC4;&#x4EF6;&#x4F1A;&#x88AB;&#x7F13;&#x5B58;&#xFF0C;&#xFF08;&#x6CE8;&#x610F;&#x662F;&#x7EC4;&#x4EF6;&#x7684;&#x540D;&#x5B57;&#xFF0C;&#x4E0D;&#x662F;&#x8DEF;&#x7531;&#x7684;&#x540D;&#x5B57;&#xFF09;&#x5176;&#x5B83;&#x7EC4;&#x4EF6;&#x4E0D;&#x4F1A;&#x88AB;&#x7F13;&#x5B58;exclude&#x5C5E;&#x6027;&#x8868;&#x793A;&#x9664;&#x4E86;name&#x5C5E;&#x6027;&#x4E3A;indexLists&#x7684;&#x7EC4;&#x4EF6;&#x4E0D;&#x4F1A;&#x88AB;&#x7F13;&#x5B58;&#xFF0C;&#x5176;&#x5B83;&#x7EC4;&#x4EF6;&#x90FD;&#x4F1A;&#x88AB;&#x7F13;&#x5B58;</p>
</li>
<li><p>&#x5229;&#x7528;meta&#x5C5E;&#x6027;</p>
<pre><code>export default[
 {
  path:&apos;/&apos;,
  name:&apos;home&apos;,
  components:Home,
  meta:{
    keepAlive:true //&#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x7EC4;&#x4EF6;
 },
 {
  path:&apos;/book&apos;,
  name:&apos;book&apos;,
  components:Book,
  meta:{
     keepAlive:false //&#x4E0D;&#x9700;&#x8981;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x7EC4;&#x4EF6;
 } 
]
</code></pre><pre><code>&lt;keep-alive&gt;
  &lt;router-view v-if=&quot;this.$route.meat.keepAlive&quot;&gt;&lt;/router-view&gt;
  &lt;!--&#x8FD9;&#x91CC;&#x662F;&#x4F1A;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x7EC4;&#x4EF6;--&gt;
&lt;/keep-alive&gt;
&lt;keep-alive v-if=&quot;!this.$router.meta.keepAlive&quot;&gt;&lt;/keep-alive&gt;
&lt;!--&#x8FD9;&#x91CC;&#x662F;&#x4E0D;&#x4F1A;&#x88AB;&#x7F13;&#x5B58;&#x7684;&#x7EC4;&#x4EF6;--&gt;
</code></pre></li>
<li><p>&#x5B98;&#x65B9;&#x63D0;&#x51FA;&#x7684;&#x89E3;&#x51B3;&#x65B9;&#x6848;<a href="https://router.vuejs.org/zh/guide/essentials/dynamic-matching.html#&#x54CD;&#x5E94;&#x8DEF;&#x7531;&#x53C2;&#x6570;&#x7684;&#x53D8;&#x5316;" target="_blank">&#x54CD;&#x5E94;&#x8DEF;&#x7531;&#x53C2;&#x6570;&#x7684;&#x53D8;&#x5316;</a></p>
</li>
<li><p>&#x5229;&#x7528;berforeRouteEnter&#x5B9E;&#x73B0;&#x524D;&#x8FDB;&#x5237;&#x65B0;&#xFF0C;&#x540E;&#x9000;&#x7F13;&#x5B58;<a href="https://juejin.im/post/5a69894a518825733b0f12f2" target="_blank">&#x8D44;&#x6599;</a></p>
</li>
<li><p><a href="https://github.com/zack24q/vue-navigation" target="_blank">&#x5229;&#x7528;&#x7B2C;&#x4E09;&#x65B9;&#x63D2;&#x4EF6;</a>&#x5B9E;&#x73B0;&#x524D;&#x8FDB;&#x5237;&#x65B0;&#xFF0C;&#x540E;&#x9000;&#x4E0D;&#x7F13;&#x5B58;</p>
</li>
</ol>
<p>&#x4F5C;&#x8005;&#xFF1A;&#x7F8A;&#x70CA;&#x7FB4;</p>
<p>&#x94FE;&#x63A5;&#xFF1A;<a href="https://www.jianshu.com/p/4b55d312d297" target="_blank">https://www.jianshu.com/p/4b55d312d297</a></p>
<p>&#x6765;&#x6E90;&#xFF1A;&#x7B80;&#x4E66;</p>
<p>&#x7B80;&#x4E66;&#x8457;&#x4F5C;&#x6743;&#x5F52;&#x4F5C;&#x8005;&#x6240;&#x6709;&#xFF0C;&#x4EFB;&#x4F55;&#x5F62;&#x5F0F;&#x7684;&#x8F6C;&#x8F7D;&#x90FD;&#x8BF7;&#x8054;&#x7CFB;&#x4F5C;&#x8005;&#x83B7;&#x5F97;&#x6388;&#x6743;&#x5E76;&#x6CE8;&#x660E;&#x51FA;&#x5904;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="TypeError Cannot read property 'compilation' of undefined.html" class="navigation navigation-prev " aria-label="Previous page: TypeError Cannot read property 'compilation' of undefined">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Vue - 过渡与动画transition.html" class="navigation navigation-next " aria-label="Next page: Vue - 过渡与动画transition">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Vue  keep-alive","level":"1.24","depth":1,"next":{"title":"Vue - 过渡与动画transition","level":"1.25","depth":1,"path":"project/Vue - 过渡与动画transition.md","ref":"project/Vue - 过渡与动画transition.md","articles":[]},"previous":{"title":"TypeError Cannot read property 'compilation' of undefined","level":"1.23","depth":1,"path":"project/TypeError Cannot read property 'compilation' of undefined.md","ref":"project/TypeError Cannot read property 'compilation' of undefined.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"project/Vue  keep-alive.md","mtime":"2019-06-15T10:47:21.782Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-07-18T03:07:23.077Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

